<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Registration and Login Form</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">
<!--
var validationsRegister = new Array();
var validationsLogin = new Array();
// Define which validations to perform. Each array item
// holds the form field to validate, and the validation
// to be applied. This is the only part you need to
// customize in order to use the script in a new page!
validationsRegister[0]=["document.registerForm.username", "notblank"];
validationsRegister[1]=["document.registerForm.useremail", "validemail"];
validationsRegister[2]=["document.registerForm.password", "validpassword"];
validationsLogin[0]=["document.loginForm.username", "notblank"];
validationsLogin[1]=["document.loginForm.password", "validpassword"];



// Customize above array when used with a new page.


function isEmpty(s)
{
  if (s == null || s.length == 0)
    return true;
  // The test returns true if there is at least one non-
  // whitespace, meaning the string is not empty. If the
  // test returns true, the string is empty.
  return !/\S/.test(s);
}



function validateEmail(field)
{
  var s = field.value;
  if (isEmpty(s))
   {
     alert("Email field cannot be empty");
     field.focus();
     return false;
   }



  if (/[^@]+@\w+/.test(s))
       return true;
  alert("E-mail not in valid form. e.g.: a@b.com");
  field.focus();
  return false;
}



function validatePassword(field)

{

  var s = field.value;
  
  if (isEmpty(s))
  {
     alert("Password field cannot be empty");
     field.focus();
     return false;
   }

 return true;

}



function validateRegister()

{

  var i;

  var checkToMake;

  var field;



  for (i = 0; i < validationsRegister.length; i++)

   {

     field = eval(validationsRegister[i][0]);

     checkToMake = validationsRegister[i][1];

     switch (checkToMake)

      {

       case 'notblank': if (isEmpty(field.value))

                          {

                           alert("Username field cannot be empty");

                           field.focus();

                           return false;

                          }

                        break;

       case 'validemail':  if (!validateEmail(field))

                               return false;

                           break;

       case 'validpassword':  if (!validatePassword(field))

                            return false;

      }

   }

  //register into database
  sendEmail();

  return true;

}

function validateLogin()

{

  var i;

  var checkToMake;

  var field;



  for (i = 0; i < validationsLogin.length; i++)

   {

     field = eval(validationsLogin[i][0]);

     checkToMake = validationsLogin[i][1];

     switch (checkToMake)

      {

       case 'notblank': if (isEmpty(field.value))

                          {

                           alert("Field may not be empty");

                           field.focus();

                           return false;

                          }

                        break;


       case 'validpassword':  if (!validatePassword(field))

                            return false;

      }

   }

  return true;

}



//-->

</script>




</head>

<body>


<form name="registerForm" id="registerForm" method="post"

 action="sendmail.php"

 onsubmit="return validateRegister();">



Username:

<input type="text" name="username" id="username"

           size="30" maxlength="60" />

<br />

Email:

<input type="text" name="useremail" id="useremail"

        size="30" maxlength="90" />

<br />

Password:

<input type="text" name="password"

       id="password" size="10" maxlength="10" />

<br />

<input type="submit" value="Register" />

</form>

<br />
OR
<br />
<br />

<form name="loginForm" id="loginForm" method="get"

 action="management.php"

 onsubmit="return validateLogin();">



Username:

<input type="text" name="username" id="username"

           size="30" maxlength="60" />

<br />

Password:

<input type="text" name="password"

       id="loginpassword" size="10" maxlength="10" />

<br />

<input type="submit" value="Login" />

</form>







</body>



</html>
